package com.study.spark.scala.summer.service

import com.study.spark.scala.summer.common.TService
import com.study.spark.scala.summer.dao.WordCountDao

class WordCountService extends TService{
  private val wordCountDao = new WordCountDao

  def analysis() = {
    val lines = wordCountDao.readFile("output/test.txt")
    // TODO 2.将每一行的字符串切分
    val words = lines.flatMap(
      str => {
        str.split(" ")
      })

    // TODO 3.将切分好的相同的单词分为一组
    val wordGroup: Map[String, List[String]] = words.groupBy(str => str)

    // TODO 4.每一组单词进行数量统计
    // 如果在进行数据转换时不涉及k，只是对v进行处理，可以是以mapValues方法
    val wordcount = wordGroup.mapValues(
      str => str.size
    )
    wordcount
  }
}
